﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace H2TWindowsForms
{
    public partial class Frm_login : Form
    {
        H2TService.WebService1 service = new H2TService.WebService1();
        public Frm_login()
        {
            InitializeComponent();

        }

        private void btnlogin_Click(object sender, EventArgs e)
        {
            Login();
        }


        public void Login()
        {
            bool result = false;
            if (txtusername.Text == "" || txtpassword.Text == "")
            {
                MessageBox.Show("Miss username or password", "Warning", MessageBoxButtons.OK);
            }
            else
            {
                result = service.Login(txtusername.Text, txtpassword.Text);
                if (result == true)
                {
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Wrong username or password", "Warning", MessageBoxButtons.OK);
                    txtusername.Text = "";
                    txtpassword.Text = "";
                }
            }
        }

        private void txtpassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                Login();
            }
        }


    }
}
